<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>js面向对象</title>
		<script type="text/javascript">
			// 使用{}定义一个对象
			var stu0 = {
				// 属性
				stuName:"小明",
				stuAge:20,
				stuNum:"150001",
				// 行为
				doStudying:function(){
					console.info(this.stuName +" is studying...");
				},
				doSleeping:function(){
					console.info(this.stuName + " is sleeping...")
				}
			};
			
			// 调用该对象的行为方法
			stu0.doSleeping();
			
			// 使用构造函数定义一个对象
			
			function Student(stuName,stuAge,stuNum){
				// 属性
				this.stuName = stuName;
				this.stuAge = stuAge;
				this.stuNum = stuNum;
				this.stuCardId; // 没有初始化赋值则默认为undefined
				// 行为方法
				this.doStudying = function(){
					console.info(this.stuName +" is studying...");
					console.info("this.stuCardId="+this.stuCardId);
				};
				this.doSleeping = function(){
					console.info(this.stuName + " is sleeping...");
				}
			}
			
			// 创建给类的一个实例
			var stu1 = new Student("小李",21,"150002");
			// 调用行为方法
			stu1.doStudying();
		</script>
	</head>
	<body>
	</body>
</html>
